//
//  UITextField+Placeholder.m
//  OnionHome
//
//  Created by fengjie on 2019/10/12.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "UITextField+Placeholder.h"
#import <objc/message.h>


@implementation UITextField (Placeholder)

/*
 *【设置占位文字的颜色】
 */
- (void)setPlaceholderColor:(UIColor *)placeholderColor{
    
    // 给成员属性赋值 runtime给系统的类添加成员属性
    // 添加成员属性
    objc_setAssociatedObject(self, @"placeholderColor", placeholderColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    // 获取占位文字label控件
    UILabel *placeholderLabel = [self valueForKey:@"placeholderLabel"];
    // 设置占位文字颜色
    placeholderLabel.textColor = placeholderColor;
}
- (UIColor *)placeholderColor{
    return objc_getAssociatedObject(self, @"placeholderColor");
}

-(void)setPlaceholderFont:(UIFont *)placeholderFont{
    objc_setAssociatedObject(self, @"placeholderFont", placeholderFont, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    // 获取占位文字label控件
    UILabel *placeholderLabel = [self valueForKey:@"placeholderLabel"];
    // 设置占位文字颜色
    placeholderLabel.font = placeholderFont;
}
-(UIFont *)placeholderFont{
    return objc_getAssociatedObject(self, @"placeholderFont");
}
@end
